# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lame
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.100
pkgrel=1
pkgdesc="A high quality MPEG Audio Layer III (MP3) encoder (mingw-w64)"
arch=('any')
url="https://lame.sourceforge.io/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-mpg123"
             "${MINGW_PACKAGE_PREFIX}-nasm"
             "${MINGW_PACKAGE_PREFIX}-ncurses"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libiconv")
options=('strip' 'staticlibs')
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
        0002-07-field-width-fix.all.patch
        0005-no-gtk.all.patch
        0006-dont-use-outdated-symbol-list.patch
        0007-revert-posix-code.patch
        0008-skip-termcap.patch)
sha256sums=('ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e'
            'd3ba595816761706d1e5dcf432f0b3ad8c9c6b37584032e21bf24c89e4fd0fc8'
            'cd3c8807de5b435b8e97200e369e7e8f93f7fc0eba7d44b393ede925e42d3b00'
            '21c7ee85854be00a3e8e6790911292837676f083a5c1085718bed899096d3679'
            '1e7f61456b15ceea613de8fd982b3f892340b851393d4ca4aff44395ae237ae9'
            '8fddeebd0ccdec62ede2932ce3bbe767af6ed6f06018f7f13113401d4ce06179')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i ${srcdir}/0002-07-field-width-fix.all.patch
  patch -p1 -i ${srcdir}/0005-no-gtk.all.patch
  patch -p1 -i ${srcdir}/0006-dont-use-outdated-symbol-list.patch
  patch -p1 -i ${srcdir}/0007-revert-posix-code.patch
  # tgetent() crashes under mingw64, not sure why
  patch -p1 -i ${srcdir}/0008-skip-termcap.patch

  autoreconf -fi
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-nasm \
    --enable-shared \
    --enable-static
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
